/*
 *  Copyright (C) 2009  Peter Kist & Jan Ripke
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "Logger.h"

#include <fstream>
#include <boost/thread.hpp>

namespace galaxy {
    namespace core {

        bool Logger::initialized = false;
        std::ofstream Logger::logstream;

        void Logger::initialize (const char * logfile) {
            logstream.open(logfile, std::ios_base::out);
            if (logstream.good ()) {
                initialized = true;
            }
        }

        void Logger::terminate () {
            if (logstream.good ()) {
                logstream.close ();
            }
        }

        void Logger::error (char * msg) {
            logstream << "ERROR " << boost::this_thread::get_id() << ":" << msg << std::endl;
            logstream.flush();
        }

        void Logger::error (const char * msg) {
            logstream << "ERROR " << boost::this_thread::get_id() << ":" << msg << std::endl;
            logstream.flush();
        }

        void Logger::error (std::string& msg) {
            logstream << "ERROR: " << boost::this_thread::get_id() << ":" << msg << std::endl;
            logstream.flush();
        }

        void Logger::warning (char * msg) {
            logstream << "WARNING: " << boost::this_thread::get_id() << ":" << msg << std::endl;
            logstream.flush();
        }

        void Logger::warning (const char * msg) {
            logstream << "WARNING: " << boost::this_thread::get_id() << ":" << msg << std::endl;
            logstream.flush();
        }

        void Logger::warning (std::string& msg) {
            logstream << "WARNING: " << boost::this_thread::get_id() << ":" << msg << std::endl;
            logstream.flush();
        }

        void Logger::info (char * msg) {
            logstream << "INFO: " << boost::this_thread::get_id() << ":" << msg;
            logstream.flush();
        }

        void Logger::info (const char * msg) {
            logstream << "INFO: " << boost::this_thread::get_id() << ":" << msg;
            logstream.flush();
        }

        void Logger::info (std::string& msg) {
            logstream << "INFO: " << boost::this_thread::get_id() << ":" << msg << std::endl;
            logstream.flush();
        }

        void Logger::trace (char * msg) {
            logstream << "TRACE: " << boost::this_thread::get_id() << ":" << msg << std::endl;
            logstream.flush();
        }

        void Logger::trace (const char * msg) {
            logstream << "TRACE: " << boost::this_thread::get_id() << ":" << msg << std::endl;
            logstream.flush();
        }

        void Logger::trace (std::string& msg) {
            logstream << "TRACE: " << boost::this_thread::get_id() << ":" << msg << std::endl;
            logstream.flush();
        }

    } // namespace core
} // namespace galaxy

